package panda.rmi.server.impl;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import panda.rmi.server.ServerConnection;
import panda.rmi.server.ServerStatement;
import panda.transaction.Transaction;

/**
 * 
 * @author Tian Yuan
 *
 */
public class PandaServerConnection extends UnicastRemoteObject implements ServerConnection {
	private Transaction tx;

	protected PandaServerConnection() throws RemoteException {
		super();
		tx = new Transaction();
		// TODO Auto-generated constructor stub
	}

	@Override
	public void close() throws RemoteException {
		tx.commit();

	}

	@Override
	public ServerStatement createStatement() throws RemoteException {
		return new PandaServerStatement(this);
	}
	
	Transaction getTransaction() {
		return tx;
	}
	
	void rollback() {
		//TODO Modify this!!!
//		tx.rollback();
		tx = new Transaction();
	}
	
	void commit() {
		tx.commit();
		tx = new Transaction();
	}
}
